package com.collect.cameroon.zhiScene.v2.zhiPerfermanceV2;

import android.content.Context;

import com.collect.cameroon.zhiBase.BasePresenter;
import com.collect.cameroon.zhiBase.BaseSubscriber;
import com.collect.cameroon.zhiBean.zhiReceive.ZHIRPerfermanceListEntity;
import com.collect.cameroon.zhiBean.zhiSend.ZHISPerfermanceEntity;
import com.collect.cameroon.zhiNetApi.ZHIHttpApiProvider;
import com.collect.cameroon.zhiNetApi.ZHIHttpResponse;
import com.collect.cameroon.zhiUtils.RxSchedulers;

import javax.inject.Inject;

public class ZHIPerfermancePresenter extends BasePresenter<ZHIPerfermanceContract.View> implements ZHIPerfermanceContract.Presenter {

    @Inject
    public ZHIPerfermancePresenter() {

    }

    @Override
    public void getLatestPerfermanceListV2(Context context, final ZHISPerfermanceEntity zhisPerfermanceEntity, boolean showDialog) {
        BaseSubscriber<ZHIHttpResponse<ZHIRPerfermanceListEntity>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ZHIRPerfermanceListEntity>>(context, this, showDialog) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ZHIRPerfermanceListEntity listEntity = (ZHIRPerfermanceListEntity) object;
                            mView.onGetLatestPerfermanceListV2(listEntity, zhisPerfermanceEntity);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().perfermanceListV2(zhisPerfermanceEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }
}

